package com.ywang.puremvc.impl;

import com.ywang.puremvc.exception.NoSupportedMediator;
import com.ywang.puremvc.exception.RegisterCommandError;
import com.ywang.puremvc.framework.ICommand;
import com.ywang.puremvc.framework.IFacade;
import com.ywang.puremvc.framework.IMediator;
import com.ywang.puremvc.framework.INotification;
import com.ywang.puremvc.framework.IProxy;

/**
 * @author ywang
 */
public abstract class Facade implements IFacade {
	
	private static Facade instance;
	public static Facade getInstance() {
		return instance;
	}
	
	public static void setInstance(Facade instance) {
		Facade.instance = instance;
	}
	
	
	// handle controller
    public void initializeController() {
        Controller.getInstance();
    }
    
    public void registerCommand(Class<ICommand> clazz)
			throws RegisterCommandError {
		Controller.getInstance().registerCommand(clazz);
	}
    
    public ICommand retrieveCommand(String toDo) {
		return Controller.getInstance().retrieveCommand(toDo);
    }
    
    public void removeCommand(String toDo) {
		Controller.getInstance().removeCommand(toDo);
    }
    
    @Override
    public void sendNotification(INotification notification) {
    	
    }
    
    
    // handle view
    public void initializeView() {
        View.getInstance();
    }
    
    public void registerMediator(IMediator mediator) {
    	View.getInstance().registerMediator(mediator);
    }
    
    public IMediator retrieveMediator(String what) throws NoSupportedMediator {
    	return View.getInstance().retrieveMediator(what);
    }
    
    public void removeMediator(String what) {
    	View.getInstance().removeMediator(what);
    }
    
    public abstract void show(String what);
    
    
    // handle model
    public void initializeModel() {
        Model.getInstance();
    }
    
    public void registerProxy(IProxy proxy) {
    	Model.getInstance().registerProxy(proxy);
    }
    
    public IProxy retrieveProxy(String name) {
    	return Model.getInstance().retrieveProxy(name);
    }
    
    public void removeProxy(String name) {
    	Model.getInstance().removeProxy(name);
    }
}
